<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        Array.prototype.bucketSort = function(num) {
        function swap(arr, i, j) {
            const temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp
        }

        const max = Math.max(...this)
            console.log('最大值' + max)
        const min = Math.min(...this)
            console.log('最小值' +  min)


        const buckets = []
        const bucketsSize = Math.floor((max - min) / num) + 1
            console.log(bucketsSize)

        for(let i = 0; i < this.length; i++) {
            const index = ~~(this[i] / bucketsSize)
            !buckets[index] && (buckets[index] = [])
            buckets[index].push(this[i])
            let l = buckets[index].length
            while(l > 0) {
            buckets[index][l] < buckets[index][l - 1] && swap(buckets[index], l, l - 1)
            l--
            }
        }
        let wrapBuckets = []
        for(let i = 0; i < buckets.length; i++) {
            buckets[i] && (wrapBuckets = wrapBuckets.concat(buckets[i]))
        }
        return wrapBuckets
        }
        const arr = [11, 9, 6, 8, 1, 3, 5, 1, 1, 0, 100]
        console.log(arr.bucketSort(10))
    </script>
</body>
</html>